package com.luke.web.controller.system;

import java.util.ArrayList;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.luke.common.annotation.Log;
import com.luke.common.core.controller.BaseController;
import com.luke.common.core.domain.AjaxResult;
import com.luke.common.enums.BusinessType;
import com.luke.system.domain.TbDatas;
import com.luke.system.service.ITbDatasService;
import com.luke.common.utils.poi.ExcelUtil;
import com.luke.common.core.page.TableDataInfo;

/**
 * tbDatasController
 * 
 * @author luke
 * @date 2021-06-23
 */
@RestController
@RequestMapping("/system/tbDatas")
public class TbDatasController extends BaseController
{
    @Autowired
    private ITbDatasService tbDatasService;

    /**
     * 查询tbDatas列表
     */
    @PreAuthorize("@ss.hasPermi('system:tbDatas:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbDatas tbDatas)
    {
        startPage();
        List<TbDatas> list = tbDatasService.selectTbDatasList(tbDatas);
        List<String> q=new ArrayList<>();
        for (TbDatas datas : list) {
            q.add(datas.getSingleSeq());
        }
        List<TbDatas> list1=tbDatasService.selectTbDatasList1(q);
        TableDataInfo tableDataInfo=getDataTable(list);
        tableDataInfo.setRows(list1);
        return tableDataInfo;
    }

    /**
     * 导出tbDatas列表
     */
    @PreAuthorize("@ss.hasPermi('system:tbDatas:export')")
    @Log(title = "tbDatas", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TbDatas tbDatas)
    {
        List<TbDatas> list = tbDatasService.selectTbDatasList(tbDatas);
        ExcelUtil<TbDatas> util = new ExcelUtil<TbDatas>(TbDatas.class);
        return util.exportExcel(list, "tbDatas数据");
    }

    /**
     * 获取tbDatas详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:tbDatas:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tbDatasService.selectTbDatasById(id));
    }

    /**
     * 新增tbDatas
     */
    @PreAuthorize("@ss.hasPermi('system:tbDatas:add')")
    @Log(title = "tbDatas", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbDatas tbDatas)
    {
        return toAjax(tbDatasService.insertTbDatas(tbDatas));
    }

    /**
     * 修改tbDatas
     */
    @PreAuthorize("@ss.hasPermi('system:tbDatas:edit')")
    @Log(title = "tbDatas", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbDatas tbDatas)
    {
        return toAjax(tbDatasService.updateTbDatas(tbDatas));
    }

    /**
     * 删除tbDatas
     */
    @PreAuthorize("@ss.hasPermi('system:tbDatas:remove')")
    @Log(title = "tbDatas", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbDatasService.deleteTbDatasByIds(ids));
    }
}
